import axios from 'axios';

const API_URL = 'http://localhost:8082/api/books';

export const bookService = {
  // 获取图书列表
  getBooks: async (params) => {
    const response = await axios.get(API_URL, { params });
    return response.data;
  },

  // 创建新图书
  createBook: async (bookData) => {
    const response = await axios.post(API_URL, bookData);
    return response.data;
  },

  // 更新图书信息
  updateBook: async (id, bookData) => {
    const response = await axios.put(`${API_URL}/${id}`, bookData);
    return response.data;
  },

  // 删除图书
  deleteBook: async (id) => {
    const response = await axios.delete(`${API_URL}/${id}`);
    return response.data;
  }
};
// 获取热门图书
export const getHotBooks = (params) => axios.get('http://localhost:8082/api/books/hot', { params });
// 借阅图书
export const borrowBook = (bookId, userId) => axios.post('http://localhost:8082/api/borrows', null, { params: { bookId, userId } });
// 获取借阅记录
export const getBorrowRecords = (userId) => axios.get('http://localhost:8082/api/borrows', { params: { userId } });
// 归还图书
export const returnBook = (borrowId) => axios.put('http://localhost:8082/api/borrows/return', null, { params: { borrowId } });